# 牙膏的销售量的线性回归模型，读取excel与文本文件

import pandas as pd
import scipy.stats as st
import matplotlib.pyplot as plt
import os
import numpy as np
import statsmodels.api as sm
data = np.genfromtxt('data2.txt', delimiter="\t", encoding='utf-8')  # 文件内容是gbk，在windows下默认读取gbk，需要设置utf-8
print(data)
y = data[:, [4]]
x = data[:, 1:4]
print(x)
x = sm.add_constant(x)
model = sm.OLS(y, x).fit()
print(model.params)
# print(x)
# print(y)

model.summary()
print(model.mse_model)




# data = pd.read_excel('data.xlsx')
# # data = np.genfromtxt('data.txt', delimiter="\t")
# data = data.to_numpy()
# # print(data)
# # print(type(data))
# y = data[:, [0]]
# x = data[:, 1:]
# x = sm.add_constant(x)
# model = sm.OLS(y, x).fit()
# # print(x)
# # print(y)
# #
# # ones = np.ones(len(x[0]))
# #
# # model = sm.ols('不良贷款~各项贷款余额', data).fit()
# print(model.summary())
#
#
